package com.fuful;

import com.fuful.domian.Orders;
import com.fuful.domian.OrdersDetails;
import com.fuful.domian.Products;
import com.fuful.domian.Users;
import com.fuful.mappers.OrdersMapper;
import com.fuful.mappers.ProductsMapper;
import com.fuful.mappers.UsersMapper;
import com.fuful.service.OrdersService;
import com.fuful.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
//        SqlSession sqlSession = MybatisUtil.getSqlSession();
//
//        UsersMapper usersMapper = sqlSession.getMapper(UsersMapper.class);
//
//        usersMapper.addUsers(new Users("hobe","qaz123"));
//        //非查询查询操作必须手动提交
//        sqlSession.commit();
//        Users users= usersMapper.findByUserName("my");
//        System.out.println(users.getUname() + "-----" + users.getUpwd());
//        List<Users> data = usersMapper.findByAll();
//        List<Users> data = usersMapper.findByLikeUserName("%m%");
//        for (Users u: data) {
//            System.out.println(u.getUname() + "-----" + u.getUpwd());
//        }
//        int flag = usersMapper.updateUpwd(6,"q123456");
//        Users u = new Users();
//        u.setUid(30);
//        Users u2 = new Users();
//        u2.setUid(31);
//        List<Users> data = new ArrayList<>();
//        data.add(u);
//        data.add(u2);
//        int flag = usersMapper.delManyUsers(data);
//        sqlSession.commit();
//        System.out.println(flag);
//        ProductsMapper mapper = sqlSession.getMapper(ProductsMapper.class);
//        List<Products> data = mapper.findByPName("雅");
//        for (Products p: data) {
//            System.out.println(p.getPname());
//            System.out.println(p.getPtid().getPtname());
//        }
//        OrdersMapper ordersMapper = sqlSession.getMapper(OrdersMapper.class);
//        Orders orders = ordersMapper.findByOrderId("2020091509474140599324");
//        System.out.println(orders.getOrderid());
//        System.out.println(orders.getUid().getUname());
//        System.out.println(orders.getOrderprice());
//        List<OrdersDetails> ordersDetailsList = orders.getDetails();
//        for (OrdersDetails od: ordersDetailsList) {
//            System.out.println(od.getPid().getPname());
//            System.out.println(od.getNum());
//        }
//        MybatisUtil.closeSqlSession();
        OrdersService os = new OrdersService();
        Users users = new Users();
        users.setUid(6);
        Map<Products,Integer> cart = new HashMap<>();
        Products p = new Products();
        p.setPid(1);
        p.setPprice(12.8f);
        Products p2 = new Products();
        p2.setPid(2);
        p2.setPprice(1.0f);
        cart.put(p,4);
        cart.put(p2,6);
        boolean succ =os.createUsersOrder(users,cart);
        System.out.println(succ);
    }
}
